<?php
class Js extends CI_Controller {
	
	function __construct(){
		parent::__construct();
		
		$this->load->driver('cache', 
			array('adapter' => 'apc', 'backup' => 'file')
		);		
	}	
	
	function _remap($method){
		$this->_inlinejs($method);
	}
	
	/**
	 * Display inline scripting.
	 * 
	 * @return void
	 */
	function _inlinejs($checksum=null){
		
		if(is_null($checksum))
			show_404();
			
		$checksum = str_replace(".js","", $checksum);
		
		$this->load->driver('cache');
		
		$content =  $this->cache->get($checksum);

		if(!$content)
			show_404();

		$this->output->set_header('Content-type: text/javascript');
		$this->output->set_header("Cache-Control: public");
		$this->output->set_header("Pragma: public"); 
		
		$expire_date = date("D, d M Y H:i:s e", time() + (20*24*60*60) );
		
		$this->output->set_header("Expires: {$expire_date}");
		$this->output->set_header("Etag: {$checksum}");
		
		$this->output->cache(20*24*60);

		ci_echo($content);

		$this->cache->delete($checksum);
	}
}